package org.onvivals.app.modules.pms.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onvivals.app.modules.auth.util.SaTokenUtil;
import org.onvivals.common.web.Result;
import org.onvivals.module.pms.service.IPmsCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
@Tag(name = "小程序:激活码")
@RequestMapping("/code")
public class PmsCodeController {

	private final IPmsCodeService pmsCodeService;

	/**
	 * 检查激活码是否可用
	 */
	@GetMapping("/checkCode")
	@Operation(summary = "检查激活码是否可用")
	public Result<?> checkCode(@RequestParam(value = "code") String code) {
		Long userId = SaTokenUtil.getUserId();
		boolean flag =  pmsCodeService.checkCode(code,userId);
		if (flag){
			return Result.OK("激活码可用");
		}
		return Result.error("激活码不可用");
	}
}
